# frozen_string_literal: true

module SchemaSeed
  AGE_SCHEMA_NAME = 'age rule'

  def self.run
    age_schema
  end

  def self.age_schema
    @schema_age ||= Schema.find_by(name: AGE_SCHEMA_NAME)
    return @schema_age if @schema_age

    @schema_age = Schema.create!(
      name: AGE_SCHEMA_NAME,
      status: Schema::Status::DEPLOYED,
      description: 'age rule description'
    )
    @schema_age.schema_variables.create!([
      {
        variable_type: VariableType.find_by(name: 'integer'),
        name: 'age',
        ordinal: 0,
        io_type: SchemaVariable::IoType::INPUT,
        required: true
      },
      {
        variable_type: VariableType.find_by(name: 'string'),
        name: 'result',
        ordinal: 0,
        io_type: SchemaVariable::IoType::OUTPUT,
        required: true
      }
    ])
    @schema_age
  end
end
